<template>
  <div class="table">
    <!-- 表格 -->
    <el-table
      :data="menulist"
      border
      style="width: 100%"
      row-key="id"
      :tree-props="{ children: 'children' }"
      default-expand-all
    >
      <el-table-column prop="id" label="菜单编号" width="180"></el-table-column>
      <el-table-column
        prop="title"
        label="菜单名称"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="pid"
        label="上级菜单"
        width="100%"
      ></el-table-column>
      <el-table-column label="菜单图标">
        <!-- 开辟一个作用域槽口  用于修改数据内容   item随便自定义的    row是固定的每一行的   item.row每一行的数据 -->
        <template slot-scope="item">
          <div>
            <i :class="item.row.icon"></i>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="item">
          <div>
            {{ item.row.status == 1 ? "启用" : "禁用" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="id" label="操作">
        <template slot-scope="item">
          <div>
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              circle
              @click="edit(item.row.id)"
            ></el-button>
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              circle
              @click="menuAdd(item.row.id)"
            ></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
//引人vuex辅助性函数
import { delMenudelete } from "../../request/api";
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      menulist: "menu/getMenu",
    }),
  },
  mounted() {
    //页面一加载就调用接口地址
    this.getMenuAction();
  },
  methods: {
    //取消按钮
    edit(id) {
      this.$emit("edit", id);
    },
    ...mapActions({
      getMenuAction: "menu/getMenuAction",
    }),
    menuAdd(id) {
      this.$confirm("确认要删除此数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delMenudelete({ id }).then((res) => {
            if (res.code == 200) {
              this.$message.success(res.msg);
            } else {
              this.$message.error(res.msg);
            }
          });
          this.getMenuAction();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>
<style scoped>
</style>